import flipClock from '../../components/payDate/FlipClock'
export default {
  data() {
    return {
      // Core,
      deposit_amount: '',
      payType: '',
      url: '',
      oid: '',
      yuer: 0,
      waittimer: '',
      isShow: true,
      dingj: '',
      stuas: 0,
      mShow6: false,
      mShowye: false
    }
  },

  computed: {
    serviceNumber(){
      return this.$store.state.serviceNumber
    }
  },
  onLoad(option) {

    this.oid = option.id
    // this.deposit_amount=option.deposit_amount
    this.deposit_amount = 2000
    // this.waittimer=option.time
    this.waittimer = '2020/11/19 09:57:13'
    console.log(this.waittimer)
    this.getTime()
  },
  components: {
    flipClock
  },
  // 监听返回按钮 记得return true
  onBackPress(options) {
    if (options.from === 'backbutton') {
      this.mShowye = true
      return true
    }
  },
  methods: {
    // 不同的支付方式分开处理
    goType() {
      uni.navigateTo({
        url: '/pages_commodity/paySuccessful/paySuccessful'
      })

      // if (this.payType == 2) {
      //   this.mShowye = true
      // } else {
      //   setTimeout(function() {
      //     this.mShow6 = true
      //   }, 2000)
      //   this.goPay()
      // }
    },
    async goPay() {
      console.log(11111)
      let data = {
        // this.oid
        'contractid': this.oid,
        'type': this.payType //type（0、微信 1、支付宝 2、余额）
      }

      if (this.payType !== '') {

        let res = await this.$api.pay.PayDepositAsync(data)
        try {
          console.log('支付结果', res, this.payType)
          if (res.code === 200) {
            this.url = res.data
            var abc = this.url.substring(this.url.indexOf('?') + 2)
            if (this.payType === '0') {
              // 分解参数 跳转页面 跳转到webview页面
              let id = this.url.split('prepay_id=')[1].split('&package=')[0]
              let pack = this.url.split('&package=')[1]
              uni.navigateTo({
                url: '/pages_order/payLoading/payLoading?paytype=0&package=' + pack + '&id=' + id + '&dealId=' +
                  this.oid
              })

            } else if (this.payType === '1') {
              // 调起支付宝支付 orderInfo为string类型  微信为object类型
              uni.requestPayment({
                provider: 'alipay',
                orderInfo: res.data,
                success: function(res) {
                  console.log('success:', res)
                },
                fail: function(err) {
                  console.log('fail:', res)
                  this.mShow6 = false
                },
                complete: () => {
                  this.mShow6 = true
                }
              })

            } else {
              this.mShowye = false
              this.confirmHE()
            }
          }
        } catch (err) {
          console.log(err)
        }
      } else {
        this.mShowye = false
      }

    },

    call() {
      AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
      uni.makePhoneCall({
        phoneNumber: this.serviceNumber.number
      })
    },

    radioChange(val) {
      this.payType = val.detail.value
    },
    getTime() {
      // var parmeter = {
      // 	contractid: this.oid,
      // 	userid: Core.CurrentUser().uid
      // };
      // Core.AjaxPost(Core.Bus.QueryTime, parmeter, res => {
      // 	this.timer = res.data.Item.dateDiff
      // 	this.yuer = res.data.Item.balance
      // 	this.dingj = res.data.Item.depositamount
      // 	this.isShow = true
      // })
    },
    // 余额
    confirmYe() {
      console.log(1111, '余额')
      this.goPay()
    },
    // 支付宝微信
    confirmHE() {
      uni.redirectTo({
        // type 支付方式  paytype支付类型 0订单 1保证金
        url: '/pages_common/pages_me/paySuccess/paySuccess?type=' + this.payType + '&id=' + this.oid + '&paytype=0'
      })
    },
    //取消支付
    quxiaocliick() {
      this.mShowye = false
      uni.switchTab({
        url: '/pages/me/me'
      })

    },

  }
}
